<?php

ini_set( "php_value upload_max_filesize", "30M" );
ini_set( "php_value max_execution_time", "300" );
ini_set( "php_value max_input_time", "300" );
ini_set( "php_value memory_limit", "67108864" );
			
			
$authInfo = extractObjectWithKeyFromArray('authInfo', $_SESSION);

$selectFormId = extractNumberWithKeyFromArray("selectFormId", $_REQUEST, 0);


if($selectFormId){
	
	$debugMode = extractNumberWithKeyFromArray("debugMode", $_POST, 0);
	$addMetaLabelToDocument = extractNumberWithKeyFromArray("addMetaLabelToDocument", $_POST, 0);
	$useMetadataLookUp = extractNumberWithKeyFromArray("useMetadataLookUp", $_POST, 0);
	
	include_once("lib/CmsFormImport.php");
	$cmsFormImport = new CmsFormImport($selectFormId,&$authInfo,&$db,$debugMode,$addMetaLabelToDocument, $useMetadataLookUp);
	
	$processImport = extractNumberWithKeyFromArray("processImport", $_POST, 0);
	if($processImport){
		
		unset($_REQUEST);
		
		$message = $cmsFormImport->processImport();
		if($message->hasErrors){
		
			//echo $message->getMessageForKey('Content');
			$errMsg = $message->messages['Content'][0]['message'];
		
		}
	}
}


$query = "SELECT f.* FROM formdescriptor f WHERE f.formid > 0 AND f.activemodule='1' AND f.sidebarmodule='1'";
$db->executeQuery($query);

?>
<div id="cms_browse_heading" class="cms_browse_heading">
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td valign="top" align="left">
	<h1>Import</h1>
      </td>
      <td align="right" valign="top"></td>
    </tr>
  </table>
</div>
<div id="cms_browse_topdivider" class="cms_browse_divider"></div>

<div>
<form name="select_form" method="get" class="cms_form">
<input type="hidden" name="fileNo" value="<?=$fileNo?>">

<table border="0" width="390">
 <tr>
  <td valign="top" width="80">Module:</td>
  <td>
   <select name="selectFormId" onchange="document.select_form.submit()">
    <option value="0">-- Select module --</option>
<?
	while($row = $db->nextObject()){
?>    <option value="<?=$row->formid?>" <?if($selectFormId==$row->formid) print ' selected="selected"';?>><?=$row->formname?></option>
<?
	}
?> 
   </select>
  </td>
</table> 
  
</form>
<br />
<?
if($selectFormId){
?>
<form method="post" enctype="multipart/form-data">
<input type="hidden" name="formId" value="<?=$formid?>" />
<input type="hidden" name="processImport" value="1" />
Import CSV File: <input type="file" name="csvFile" /> 
<input type="image" name="submit" align="absmiddle" src="/cms/images/button_go.gif" />
<br />
<input type="checkbox" name="debugMode" value="1" checked="checked"/> Test Mode<br />
<input type="checkbox" name="addMetaLabelToDocument" value="1" /> Generate Search Engine Optimisation Url By Title<br/>
<input type="checkbox" name="useMetadataLookUp" value="1" checked="checked"/> Look up m-m and 1-m from metadata label<br/>
</form>
<?
if(isset($errMsg))	echo '<br /><div style="color:red">'.$errMsg.'</div>';
?>
<br />
<br />
<br />
<b>Available Labels:</b>
<div id="cms_browse_topdivider" class="cms_browse_divider"></div>

<table cellspacing="7">
<?
foreach ($cmsFormImport->availableLabels as $label){
?>
 <tr>
  <td valign="top"><span style="background-color:#eeeeee"><?=$label?></span></td>
 </tr>  
<?
}
?>

</table>
<br />
* Click <a href="/cms/html/index.php?fileNo=15&selectFormId=<?=$selectFormId?>&outputBlankSpreadsheet=1">here</a> to download a blank spreadsheet

<br />
<br />
<br />
<b>Import Rules:</b>
<div id="cms_browse_topdivider" class="cms_browse_divider"></div>
<ol>
<li>Drop down - use metadata label instead of documentcode</li>
<li>Checkbox list - use metadata label instead of documentcode</li>
<li>Checkbox list - use ; to seperate each metadata label</li>
<li>....</li>
<li>Save the file as CSV(Comma delimited), unix line feeds</li>

</ol>


<?
}
?>

</div>
